package cn.edu.zafu.bigdata.x.zcy_0217;

public class Cube {
    private double length;
    private double width;
    private double height;

    public Cube(double length, double width, double height){
        this.height=height;
        this.width=width;
        this.length=length;
    }

    public double getLength(){
        return length;
    }

    public double getHeight() {
        return height;
    }

    public double getWidth() {
        return width;
    }
    @Override
    public boolean equals(Object obj){
        if(this==obj){
            return true;
        }
        if (obj==null || getClass()!=obj.getClass()){
            return false;
        }
        if (((Cube) obj).height==this.height||((Cube) obj).length==this.length||((Cube) obj).width==this.width){
            return true;
        }else{
            return false;
        }
    }

    // 重写hashCode方法（通常与equals一起重写）
    @Override
    public int hashCode() {
        // 使用一个质数作为乘数，并将每个属性的hashCode合并
        int result;
        long temp;
        temp = Double.doubleToLongBits(length);
        result = (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(width);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(height);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        return result;
    }

}



class TestCube {
    public static void main(String[] args) {
        // 创建Cube对象
        Cube cube1 = new Cube(3.0, 4.0, 5.0);
        Cube cube2 = new Cube(3.0, 4.0, 5.0);
        Cube cube3 = new Cube(6.0, 8.0, 10.0);

        // 测试相等性
        System.out.println("cube1 equals cube2: " + cube1.equals(cube2)); // 应该输出true
        System.out.println("cube1 equals cube3: " + cube1.equals(cube3)); // 应该输出false

        // 测试与null的比较
        System.out.println("cube1 equals null: " + cube1.equals(null)); // 应该输出false

        // 测试与不同类的比较
        System.out.println("cube1 equals \"Not a Cube\": " + cube1.equals("Not a Cube")); // 应该输出false
    }
}